import React from 'react';
import {Card, List, View, Container, NavBar} from 'amazeui-touch';
import {connect} from 'react-redux';
import Action from '../store/actions';
import {bindActionCreators} from 'redux';
import {Link} from 'react-router';
import {status} from '../util'
import Loading from './Loading'

@connect(
    state => ({...state}),
    dispatch => bindActionCreators(Action, dispatch)
)
export default class Order extends React.Component {
    constructor(props) {
        super(props);
    }

    componentWillMount() {
        this.props.getOrder();
    };

    render() {
        const backNav = {
            component: Link,
            icon: 'left-nav',
            title: '返回',
            to: '/',
            onlyActiveOnIndex: true
        };

        if (this.props.home.order.orderInfo.RET_CODE === "error") {
            return (
                <View>
                    <NavBar
                        amStyle="primary"
                        title="我的订单"
                        leftNav={[backNav]}
                    />
                    <Container>
                        <div className="cartFont">
                            <Loading/>
                        </div>
                    </Container>
                </View>);
        } else {
            return (
                <View>
                    <NavBar
                        amStyle="primary"
                        title="我的订单"
                        leftNav={[backNav]}
                    />
                    <Container scrollable>
                        <div className="goods">
                            <Card>
                                <List>
                                    {this.props.home.order.orderInfo.orderList.map((item, index) => {
                                        return (
                                            <List.Item
                                                key={index}
                                                title={"订单号太长"}
                                                subTitle={"订单金额:"+item.totalPrice}
                                                after={status(item.orderStatus,item.payStatus)}
                                            />
                                        );
                                    })}
                                </List>
                            </Card>
                        </div>
                    </Container>
                </View>
            );
        }
    }
}
